package String;

public class 动态口令 {
    public String dynamicPassword(String password, int target) {
        StringBuilder sb = new StringBuilder(password);
        reverseString(sb, 0, target - 1);
        reverseString(sb, target, sb.length() - 1);
        reverseString(sb, 0, sb.length() - 1);
        return sb.toString();
    }

    private void reverseString(StringBuilder s, int left, int right) {
        while (left < right) {
            char temp = s.charAt(left);
            s.setCharAt(left, s.charAt(right));
            s.setCharAt(right, temp);
            left++;
            right--;
        }
    }
}
